package com.jms.framework.beans.creator;

import com.jms.framework.beans.BeanDefinition;
import com.jms.framework.beans.ChildBeanDefinition;
import com.jms.framework.beans.GeneralBeanDefinition;
import com.jms.framework.beans.annotation.Component;
import com.jms.framework.beans.factory.ChildBeanFactory;
import com.jms.framework.beans.factory.GeneralBeanFactory;
import com.jms.framework.beans.factory.ObjectFactory;
import com.jms.framework.context.ApplicationContext;
import com.jms.framework.exception.DataNotLegitimateException;
@Component
public class GeneralSingletonBeanFactoryCreator extends SingletonBeanFactoryCreator {

    public GeneralSingletonBeanFactoryCreator() {
        super(999999);
    }

    @Override
    public ObjectFactory<?> create(BeanDefinition beanDefinition, ApplicationContext applicationContext) {
        if (ChildBeanDefinition.class.equals(beanDefinition.getClass())) {
            return new ChildBeanFactory<>((ChildBeanDefinition) beanDefinition, applicationContext.getBeanContext());
        }
        if (GeneralBeanDefinition.class.equals(beanDefinition.getClass())) {
            return new GeneralBeanFactory<>(beanDefinition);
        }
        throw new DataNotLegitimateException("Unrecognized bean definition type: " + beanDefinition.getClass().getName());
    }
}
